package com.ruoyi.business.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.domain.CzProcess;
import com.ruoyi.business.service.ICzProcessService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 流程Controller
 * 
 * @author ruoyi
 * @date 2022-01-09
 */
@Api(tags = "流程")
@RestController
@RequestMapping("/business/process")
public class CzProcessController extends BaseController
{
    @Autowired
    private ICzProcessService czProcessService;

    /**
     * 查询流程列表
     */
    @ApiOperation(value = "查询流程列表")
    @PreAuthorize("@ss.hasPermi('business:process:list')")
    @GetMapping("/list")
    public TableDataInfo list(CzProcess czProcess)
    {
        startPage();
        List<CzProcess> list = czProcessService.selectCzProcessList(czProcess);
        return getDataTable(list);
    }

    /**
     * 导出流程列表
     */
    @ApiOperation(value = "导出流程列表")
    @PreAuthorize("@ss.hasPermi('business:process:export')")
    @Log(title = "流程", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CzProcess czProcess)
    {
        List<CzProcess> list = czProcessService.selectCzProcessList(czProcess);
        ExcelUtil<CzProcess> util = new ExcelUtil<CzProcess>(CzProcess.class);
        util.exportExcel(response, list, "流程数据");
    }

    /**
     * 获取流程详细信息
     */
    @ApiOperation(value = "获取流程详细信息")
    @PreAuthorize("@ss.hasPermi('business:process:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(czProcessService.selectCzProcessById(id));
    }

    /**
     * 新增流程
     */
    @ApiOperation(value = "新增流程")
    @PreAuthorize("@ss.hasPermi('business:process:add')")
    @Log(title = "流程", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CzProcess czProcess)
    {
        return toAjax(czProcessService.insertCzProcess(czProcess));
    }

    /**
     * 修改流程
     */
    @ApiOperation(value = "修改流程")
    @PreAuthorize("@ss.hasPermi('business:process:edit')")
    @Log(title = "流程", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CzProcess czProcess)
    {
        return toAjax(czProcessService.updateCzProcess(czProcess));
    }

    /**
     * 删除流程
     */
    @ApiOperation(value = "删除流程")
    @PreAuthorize("@ss.hasPermi('business:process:remove')")
    @Log(title = "流程", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(czProcessService.deleteCzProcessByIds(ids));
    }
}
